<?php
/**
 * 集点首页
 */

define('IN_ECS',true);
require_once(dirname(dirname(__FILE__)).'/includes/init.php');
require_once(dirname(dirname(__FILE__)).'/extension/gatherdot.php');
$action = isset($_GET['act'])?$_GET['act']:'';
if (empty($action)) {
	echo "wrong request";
	exit();
}

$openid = isset($_REQUEST['openid'])?$_REQUEST['openid']:'';



if ($action == 'index') {
	// $sql = "SELECT  * FROM ".$GLOBALS['ecs']->table('gatherdot_user').
	// 	" WHERE  openid = '$openid'";
	// $datalist = $GLOBALS['db']->getAll($sql);
//	var_dump($datalist);
	// foreach ($datalist as $k => $val) {
	// 	$g_u_id = $val['id'];
	// 	//$sql = "SELECT * FROM ".$GLOBALS['ecs']->table('');
	// }

	$ginfo = GatherDot::CurrentAct();

	if (!empty($ginfo)) {


		$gid = $ginfo['id'];
		$g_act = new GatherDot($gid);
		$datalist = $g_act->GetDotDetail($openid,$gid);
		$gatherdate = array();
		foreach ($datalist as $k => $val) {
			//$datalist[$k]['add_time'] = date('Y-m-d',$val['add_time']);
			$gatherdate[]=date('Y-m-d',$val['add_time']);
		}
	


		$start_time = $ginfo['start_time'];
		$end_time   = $ginfo['end_time'];
		$datelist = array();
		$begin = strtotime(date('Y-m-d',$start_time));
		$end   = strtotime(date('Y-m-d',$end_time));
		for ($i=strtotime(date('Y-m-d',$start_time)); $i < $end_time; $i+=86400) { 
			$tt = array();
			$tt['datevalue'] = date('Y-m-d',$i);
			if (in_array($tt['datevalue'], $gatherdate)) {
				$tt['dot'] = 1;
			}else{
				$tt['dot'] = 0;
			}
			$datelist[]=$tt;
		}

		$smarty->assign('datelist',$datelist);

		
		
	}
	$smarty->display('/weixin/VIP_jidian/vip_jidian.dwt');


}elseif($action == 'duihuan'){
$smarty->display('/weixin/VIP_jidian/vip_duihuan.dwt');
}

